package com.ojoin.ojoin.eb_spider.service.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.ojoin.ojoin.eb_spider.service.SupplyInventoryService;
import com.ojoin.trade.common.utils.CommonUtils;
import com.ojoin.trade.common.utils.LogUtils;
import com.ojoin.trade.supplyloan_core.web.domain.TbSlSupplyInventory;
@Service
public class SupplyInventoryServiceImpl implements SupplyInventoryService {
	private Logger log = LoggerFactory
			.getLogger(SupplyInventoryServiceImpl.class);
	
	@Override
	public void removeInventoryCommon(List<TbSlSupplyInventory> list,
			Map<String, TbSlSupplyInventory> MapDB) {
 
		if (!CommonUtils.isEmpty(MapDB)) {

			if (!CommonUtils.isEmpty(list)) {
				Set<String> set = MapDB.keySet();
				LogUtils.info(log, "库存数据:" + list.size());

				Iterator<TbSlSupplyInventory> it = list.iterator();
				while (it.hasNext()) {
					TbSlSupplyInventory payment = it.next();
					if (set.contains(payment.getItemKey())) {

						it.remove();

						MapDB.remove(payment.getItemKey());

						LogUtils.info(log, "库存数据:" + payment.getItemKey()
								+ "已存在");

					}
				}
			}

		} else {
			LogUtils.info(log, "库存数据:" + list.size());

			Iterator<TbSlSupplyInventory> it = list.iterator();
			while (it.hasNext()) {
				TbSlSupplyInventory payment = it.next();

				LogUtils.info(log, "库存数据:" + payment.getItemKey() + "已存在");

			}
		}

	}

	@Override
	public List<TbSlSupplyInventory> changeToPay(
			Map<String, TbSlSupplyInventory> MapDB) {
		if (null != MapDB) {
			Iterator<TbSlSupplyInventory> it = MapDB.values().iterator();
			while (it.hasNext()) {
				TbSlSupplyInventory tb = it.next();
				tb.setItemStatus(TbSlSupplyInventory.PAY);

				LogUtils.info(log, "库存单据:" + tb.getItemKey() + "状态更新"
						+ TbSlSupplyInventory.PAY);
			}

			return new ArrayList<TbSlSupplyInventory>(MapDB.values());
		}

		return null;
	}

}
